package main

import (
	"errors"
	"fmt"
)

type Account struct {
	FirstName string
	LastName  string
}

type Employee struct {
	Account
	Credits float64
}

//创建
func CreateCredits(firstName, lastName string, c float64) *Employee {
	return &Employee{Account{firstName, lastName}, c}
}

//增加
func (e *Employee) AddCredits(amount float64) (float64, error) {
	if amount > 0.0 {

		e.Credits += amount
		return e.Credits, nil

	}
	return e.Credits, errors.New("输入错误")
}

//删除
func (e *Employee) ReomveCredits(amount float64) (float64, error) {
	if amount > 0.0 {
		if amount <= e.Credits {
			e.Credits -= amount
			return e.Credits, nil
		}
	}
	return e.Credits, errors.New("输入错误")
}

//检查
func (e *Employee) checkCredits() float64 {
	return e.Credits
}

func main() {

	e := CreateCredits("wang", "heng", 22)

	e.AddCredits(1)
	fmt.Println(e.checkCredits())

}
